package com.company.refx;

import com.company.Clients;

import java.lang.reflect.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@SuppressWarnings("all")
public class refxTest {


    public void test01(Map<String, Integer> map, List<Integer> list) {

    }

    public Map<String, Integer> test02() {
        return null;
    }


    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("com.company.Clients");

        //System.out.println(Arrays.toString(clazz.getGenericInterfaces()));


//        Constructor<?> constructor = clazz.getConstructor(String.class);
//
//
//        Object o =  constructor.newInstance("在");
//
//
//
//        Field name = clazz.getDeclaredField("name");
//        name.setAccessible(true);
//        name.set(o, "aaa");
//
//        Method test = clazz.getDeclaredMethod("test",String.class);
//        test.invoke(o,"as");

        //系统加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        //扩展加载器
        ClassLoader parent = systemClassLoader.getParent();
        //根加载器
        ClassLoader parent1 = parent.getParent();
        //当前类加载器
        ClassLoader classLoader = Class.forName("com.company.refx.refxTest").getClassLoader();


        //如何获取系统类加载器可以加载的路径
       // System.out.println(System.getProperty("java.class.path"));

        //获取泛型参数信息
        Method method = refxTest.class.getMethod("test01", Map.class, List.class);

        Type[] genericParameterTypes = method.getGenericParameterTypes();
        for (Type genericParameterType : genericParameterTypes) {
            System.out.println("#" + genericParameterType);
            if(genericParameterType instanceof ParameterizedType){
                Type[] actualTypeArguments = ((ParameterizedType) genericParameterType).getActualTypeArguments();
                for (Type actualTypeArgument : actualTypeArguments) {
                    System.out.println(actualTypeArgument);
                }
            }
        }

        method = refxTest.class.getMethod("test02");
        Type genericReturnType = method.getGenericReturnType();
        if(genericReturnType instanceof ParameterizedType){
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println(actualTypeArgument);
            }
        }


        SuppressWarnings annotation = (SuppressWarnings)refxTest.class.getAnnotation(SuppressWarnings.class);
        System.out.println(annotation);
        System.out.println(annotation.value());


    }
}
